﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace WPFSample.ChooseFontSample
{
    class ChooseFont : Window
    {
        public ChooseFont()
        {
            this.Title = "Choose Font";
            Button btn = new Button()
            {
                Content = this.Title,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };
            btn.Click += this.Btn_Click;
            this.Content = btn;
        }

        private void Btn_Click(object sender, RoutedEventArgs e)
        {
            FontDialog dlg = new FontDialog();
            dlg.Owner = this;
            dlg.Typeface = new System.Windows.Media.Typeface(this.FontFamily, this.FontStyle, this.FontWeight, this.FontStretch);
            dlg.FaceSize = this.FontSize;
            if (dlg.ShowDialog().GetValueOrDefault())
            {
                this.FontFamily = dlg.Typeface.FontFamily;
                this.FontStyle = dlg.Typeface.Style;
                this.FontWeight = dlg.Typeface.Weight;
                this.FontStretch = dlg.Typeface.Stretch;
                this.FontSize = dlg.FaceSize;
            }
        }
    }
}
